package d2_collection_traverse;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class test {
    public static void main(String[] args) {
        Collection<String> co = new ArrayList<>();
        co.add("ab");
        co.add("cd");
        co.add("ef");
        co.add("gf");
        System.out.println(co);


        Iterator<String> it = co.iterator();
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println(it.next());
        System.out.println("-----------------------------------------");


        while(it.hasNext()) {
            System.out.println(it.next());
        }


        for(String s : co) {
            System.out.println(s);
        }

        String[] arr = {"ab","cd","ef","gf"};
        for(String s : arr) {
            System.out.println(s);
        }

        co.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        co.forEach((String s)->{
                System.out.println(s);
        });

        co.forEach(s->
            System.out.println(s)
        );

        co.forEach(s->
                System.out.println(s)
        );

        co.forEach(System.out::println);

    }
}
